'use strict'

/**
 * @author {JC}
 * @effect tencentCloudMessageApi
 * **/
const Service = require("egg").Service;
const tencentCloudApi = require("tencentcloud-sdk-nodejs");

class TencentCloudApi extends Service {
    async takeTencentCloudAPI(data) {

        const SmsClient = tencentCloudApi.sms.v20210111.Client;
        const clientConfig = {
            credential: {
                secretId: "",
                secretKey: ""
            },
            region: 'ap-guangzhou', // 地域信息
            profile: {
                signMethod: "HmacSHA256",
                httpProfile: {
                    reqMethod: "POST",
                    reqTimeout: 30, // 超时时间，不建议调整
                    endpoint: "sms.tencentcloudapi.com" // 默认就近接入
                }
            }
        }
        const client = new SmsClient(clientConfig); // 实例化后使用
        // TODO:请求参数
        const params = {
            // Action:"SendSms",
            // Version:"2021-01-11",
            SmsSdkAppId: "1400742404",
            SignName: "嘉徐小站",            // 备案过的签名内容
            TemplateId: "1563237", // 模板ID
            TemplateParamSet: [('000000' + Math.floor(Math.random() * 999999)).slice(-6)],
            PhoneNumberSet: [`+86${data.cellphone}`]
        }
        client.SendSms(params, (err, response) => {
            if (err) {
                return err
            }
            return response
        })
    }
}
module.exports = TencentCloudApi
